package com.myway.front.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.myway.front.dao.MyTabHotelMapper;
import com.myway.front.dao.TabHotelDictMapper;
import com.myway.front.dao.TabHotelMapper;
import com.myway.front.dao.TabHouseMapper;
import com.myway.front.param.HotelParam;
import com.myway.front.pojo.TabHotel;
import com.myway.front.pojo.TabHotelExample;
import com.myway.front.pojo.TabHouse;
import com.myway.front.pojo.TabHouseExample;
import com.myway.front.service.HotelService;
import com.myway.front.util.DataGridResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class HotelServiceImpl implements HotelService {
    @Autowired
    private MyTabHotelMapper myTabHotelMapper;

    @Autowired
    private TabHotelMapper tabHotelMapper;

    @Autowired
    private TabHotelDictMapper tabHotelDictMapper;

    @Autowired
    private TabHouseMapper tabHouseMapper;


    /**
     * 查询热门酒店
     * @param param
     * @return
     */
    @Override
    public List<TabHotel> selectHotelHomeCharact(HotelParam param) {
        TabHotelExample example = new TabHotelExample();
        TabHotelExample.Criteria criteria =example.createCriteria();
        criteria.andCityEqualTo(param.getCityHotel());
        criteria.andCharactHotelEqualTo(param.getStatusCharact());
        List<TabHotel> list=tabHotelMapper.selectByExample(example);
        if(list.size()>3){
          list=  list.subList(0,3);
        }
        return list;
    }

    /**
     * 主题酒店列表
     * @param param
     * @return
     */
    @Override
    public List<TabHotel> selectHotelHomeClassic(HotelParam param) {
        TabHotelExample example = new TabHotelExample();
        TabHotelExample.Criteria criteria =example.createCriteria();
        criteria.andHotelStyleEqualTo(param.getHotelStyle());
        criteria.andClassicHotelEqualTo(param.getStatusClassic());
        List<TabHotel> list=tabHotelMapper.selectByExample(example);
        if(list.size()>4){
            list=  list.subList(0,4);
        }
        return list;
    }

    @Override
    public DataGridResult selectHotelInf(HotelParam param, Integer page, Integer rows) {
        TabHotelExample example =new TabHotelExample();
        PageHelper.startPage((page+1),rows);
        List<TabHotel> list = myTabHotelMapper.selectHotel(param);
        DataGridResult result = new DataGridResult();
        result.setRows(list);
        PageInfo<TabHotel> pageInfo = new PageInfo<TabHotel>(list);
        result.setTotal(pageInfo.getTotal());

        return result;
    }

    /**
     * 酒店详情列表
     * @param hotelId
     * @return
     */
    @Override
    public HashMap selectHouseInf(String hotelId) {
        HashMap<String,Object> map= new HashMap<String,Object>();
        TabHotelExample example = new TabHotelExample();
        TabHotelExample.Criteria criteria = example.createCriteria();
        criteria.andNumEqualTo(hotelId);
        //返回酒店信息
        List<TabHotel> list =tabHotelMapper.selectByExample(example);
        TabHotel hote = list.get(0);
        map.put("hotel",hote);
        //处理图片组，使用逗号将其隔开，返回一个String数组。
        if(hote.getHouesPicture() != null && !(hote.getHouesPicture()).equals("")){
            String picList =hote.getHouesPicture();
            String[] piczu =picList.split(",");
            map.put("piczu",piczu);
        }
        //返回标准间列表
        TabHouseExample example1 = new TabHouseExample();
        TabHouseExample.Criteria criteria1=example1.createCriteria();
        criteria1.andHotelIdEqualTo(hotelId);
        List<TabHouse> house=tabHouseMapper.selectByExample(example1);
        if(house.size()>0){
            map.put("house",house);
        }
        return map;
    }


}
